

	var Navigation = function(config) {

	    $.extend(this, config);
	    this.layout = $(this.layout);
	    this.pageTitle = $(this.pageTitle);
	    

	    this.map = {
	    	capture: "capture",
	    	edit: "edit"
	    };

	    this.setTitle = function(title) {
	    	this.pageTitle.find("").html(title);
	    };

	    this.getCurrent = function() {
	    	return this.stack[this.stack.length - 1];
	    };

	    this.back = function(msg) {
	    	if (this.stack.length > 1) {
	    		console.log("back", this);
	    		var current = this.stack[this.stack.length - 1];
	    		var prev = this.stack[this.stack.length - 2]
	    		that = this;
				function page(strPage) {
					return that.layout.find("[data-container=" + strPage + "]");
				} 

	    		page(current).removeClass("active").addClass("next");
	    		page(prev).removeClass("prev").addClass("active");
	    		if (msg) {
	    			page(prev).find(".msg").html(msg);
	    		}

	    		this.stack.pop();
	    		//e.preventDefault();
	    		//e.stopPropagation();
	    	} 
	    };
	    this.next = function(next) {
	        var current = this.stack[this.stack.length - 1];
	        that = this;
			function page(strPage) {
				return that.layout.find("[data-container=" + strPage + "]");
			} 
    		page(current).removeClass("active").addClass("prev");
    		page(next).removeClass("next").addClass("active");
    		this.stack.push(next);
	  		// this.setTitle(this.map[this.getCurrent()]);
	  		// AppMobi.device.addVirtualPage();
	    };

	    this.stack = ["capture"];
	    // this.setTitle(this.map[this.getCurrent()]);

	}

	var Nav = new Navigation({
		layout: "[data-container=layout]",
		pageTitle: "[data-label=page-title]"
	});